package com.may.wlrj.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.async.DeferredResult;

import com.may.wlrj.services.GateWayService;

@Controller
public class GatewayController {
	private GateWayService gatewayService;
    @Autowired
    public void setGatewayService(GateWayService gatewayService){
        this.gatewayService = gatewayService;
    }
    
    @RequestMapping(value="/getgatewaylist",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
	public @ResponseBody String getgatewaylist(@RequestBody String objnode,HttpServletRequest request,HttpSession session) throws IOException{
		return gatewayService.getgatewaylist(objnode,request,session);
		
	}
    
    @RequestMapping(value = "/gatewayadd",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> gatewayadd(@RequestBody String objnode,HttpServletRequest request, HttpSession session) throws Exception{    
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        gatewayService._insertgateway(deferredResult,objnode,request, session);
        return deferredResult;
    }
    
    @RequestMapping(value = "/gatewayedit",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> gatewayedit(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws Exception{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        gatewayService._updategateway(deferredResult,objnode,request, session);
        return deferredResult;
    }
    
    @RequestMapping(value = "/gatewaydel",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> gatewaydel(@RequestBody String objnode,HttpServletRequest request ,HttpSession session) throws JsonGenerationException, JsonMappingException, IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        gatewayService._gatewayDelete(deferredResult,objnode,request ,session);
        return deferredResult;
    }
    
    @RequestMapping(value = "/gatewayoff",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> gatewayoff(@RequestBody String objnode,HttpServletRequest request ,HttpSession session) throws JsonGenerationException, JsonMappingException, IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        gatewayService._gatewayOff(deferredResult,objnode,request ,session);
        return deferredResult;
    }

    
    @RequestMapping(value = "/getGatewayoffLogs",method = RequestMethod.POST,produces="application/json;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> getGatewayoffLogs(@RequestBody String objnode,HttpServletRequest request ,HttpSession session) throws JsonGenerationException, JsonMappingException, IOException{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        gatewayService._getGatewayoffLogs(deferredResult,objnode,request ,session);
        return deferredResult;
    }

}
